package com.dhcc.core.modules.system.entity;

import com.baomidou.mybatisplus.annotations.TableName;
import com.dhcc.core.framework.base.entity.TreeEntity;
import com.dhcc.core.framework.constant.Const;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.core.framework.util.PinyinUtil;

/**
 * 部门表
 *
 * @ClassName: Dept
 * @Description: TODO
 * @author: cyf
 * @date: 2018年1月2日 上午10:35:25
 */
@TableName("sys_dept")
public class Dept extends TreeEntity<Dept> {

    private static final long serialVersionUID = 1L;

    /**
     * 部门编码
     */
    private String code;
    /**
     * HIS科室编码
     */
    private String hisCode;
    /**
     * 简称
     */
    private String name;
    /**
     * 全称
     */
    private String fullname;
    /**
     * 描述
     */
    private String description;

    /**
     * 首字母与全拼
     */
    private String initials;
    private String pinyin;
    /**
     * 部门领导
     */
    private Long leader;
    /**
     * 分管领导
     */
    private Long superior;
    /**
     * 部门分类
     */
    private String deptType;

    /**
     * 部门属性
     */
    private String deptAttr;
    /**
     * 部门分组
     */
    private String deptGroup;
    /**
     * 经度
     */
    private String longit;
    /**
     * 纬度
     */
    private String latit;
    /**
     * 外部主键
     */
    private String xcode;

    private Boolean pwdFlag;

    public String getInitials() {
        return initials;
    }

    public void setInitials(String initials) {
        this.initials = initials;
    }

    public String getPinyin() {
        return pinyin;
    }

    public void setPinyin(String pinyin) {
        this.pinyin = pinyin;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getFullname() {
        return fullname;
    }

    public void setFullname(String fullname) {
        this.fullname = fullname;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Long getLeader() {
        return leader;
    }

    public void setLeader(Long leader) {
        this.leader = leader;
    }

    public Long getSuperior() {
        return superior;
    }

    public void setSuperior(Long superior) {
        this.superior = superior;
    }
    public String getDeptType() {
        return this.deptType;
    }

    public void setDeptType(String deptType) {
        this.deptType = deptType;
    }
    public String getDeptAttr() {
        return this.deptAttr;
    }

    public void setDeptAttr(String deptAttr) {
        this.deptAttr = deptAttr;
    }
    public String getDeptGroup() {
        return this.deptGroup;
    }

    public void setDeptGroup(String deptGroup) {
        this.deptGroup = deptGroup;
    }
    public String getLongit() {
        return this.longit;
    }

    public void setLongit(String longit) {
        this.longit = longit;
    }
    public String getLatit() {
        return this.latit;
    }
    public void setLatit(String latit) {
        this.latit = latit;
    }
    public String getXcode() {
        return this.xcode;
    }
    public void setXcode(String xcode) {
        this.xcode = xcode;
    }
    public Boolean getPwdFlag() {
        return this.pwdFlag;
    }
    public void setPwdFlag(Boolean pwdFlag)
    {
        this.pwdFlag = pwdFlag;
    }

    public String getHisCode() {
        return hisCode;
    }

    public void setHisCode(String hisCode) {
        this.hisCode = hisCode;
    }

    /**
     * 根据请求的父级编号设置和层级
     */
    public void init() {
        if (CommonUtil.isEmpty(this.getParentId()) || this.getParentId() == 0) {
            this.setParentId(Const.TREE_ROOT_ID);
            this.setPath("[" + Const.TREE_ROOT_ID + "]");
            this.setLevels(1);
        } else {
            TreeEntity<?> parent = (TreeEntity<?>) this.selectById(this.getParentId());
            this.setParentId(parent.getId());
            this.setPath(parent.getPath() + ",[" + parent.getId() + "]");
            this.setLevels(parent.getLevels()+1);
        }
        this.setInitials(PinyinUtil.converterToFirstSpell(this.getName()));
        this.setPinyin(PinyinUtil.converterToSpell(this.getName()));
    }

}
